<?php
namespace app\admin\controller;

\think\Loader::import('controller/Controller', \think\Config::get('traits_path') , EXT);

use app\admin\Controller;
use think\Db;
use think\Config;

class BankCard extends Controller
{
    use \app\admin\traits\controller\Controller;
    // 方法黑名单
    protected static $blacklist = [];

    public function index(){

        $data = input();
        if ($data['user_id']) {
            $map['user_id'] = $data['user_id'];
        }
        if ($data['user_name']) {
            $map['user_name'] = $data['user_name'];
        }
        if ($data['card_num']) {
            $map['card_num'] = $data['card_num'];
        }
        if ($data['bank_name']) {
            $map['bank_name'] = $data['bank_name'];
        }

        $listRows = $this->request->param('numPerPage') ?: Config::get("paginate.list_rows");
        $list = Db::name('bank_card')
            ->where($map)
            ->order("id desc")
            ->paginate($listRows, false, ['query' => $this->request->get()]);

        // 模板赋值显示
        $this->view->assign('list', $list);
        $this->view->assign("count", $list->total());
        $this->view->assign("page", $list->render());
        $this->view->assign('numPerPage', $list->listRows());

        return $this->view->fetch();
    }


    public function edit()
    {

        $data = input();

        if($this->request->isAjax()){
            //编辑页面
            $result = Db::name('bank_card')
                ->where('id',$data['id'])
                ->update($data);
            if($result){
                return ajax_return_adv("编辑成功");
            }
        }else {
            //页面展示
            $users = Db::name('admin_user')->select();
            $result = Db::name('bank_card')
                ->where('id',$data['id'])
                ->find();
            $this->view->assign('vo',$result);
            $this->view->assign('users', $users);
            return $this->view->fetch('edit');
        }
    }
}
